//
//  PagerSubC.m
//  UniverseProject
//
//  Created by king on 2021/6/22.
//  Copyright © 2021 Cloud2209. All rights reserved.
//

#import "PagerSubCell.h"
#import "PagerSubC.h"

@interface PagerSubC ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic ,weak) UITableView *tableView;
@property (nonatomic ,strong) NSMutableArray *dataArr;
@property (assign,nonatomic) NSInteger pageNo;
@property (nonatomic, assign)NSInteger dataCount;
@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);

@end

@implementation PagerSubC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"房源";
    
    self.pageNo = 1;
    self.dataCount = 0;
    [self setupTab];
    
}

/**
 设置表格
 */
- (void)setupTab{
    

  
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, K_SCREEN_WIDTH,  K_SCREEN_HEIGHT - k_SafeAreaTopHeight - 50) style:UITableViewStylePlain];
    [self.view addSubview:tableView];
    
    self.tableView = tableView;
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.showsVerticalScrollIndicator = NO;
    self.tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    self.tableView.backgroundColor = [UIColor clearColor];
    self.tableView.estimatedRowHeight = 0;
    self.tableView.estimatedSectionHeaderHeight = 0;
    self.tableView.estimatedSectionFooterHeight = 0;
    
    kWeakSelf(self);
    
    self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        weakself.pageNo += 1;
        [weakself getUserMessageList];
    }];
    
//    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//        weakself.pageNo = 1;
//        [weakself getUserMessageList];
//    }];
    tableView.ly_emptyView = [LGDIYEmptyView diyNoDataEmptyImageName:@"newjbflszImage" Title:@"暂无数据" content:@""];
    
    UIView *boxView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, K_SCREEN_WIDTH, 80)];
    boxView.backgroundColor = [UIColor redColor];
    self.tableView.tableHeaderView = boxView;
    
}

#pragma mark -UITableView代理方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    //    return self.dataArr.count;;
    return self.dataCount;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    PagerSubCell *cell = [PagerSubCell cellWithTableView:tableView];
    cell.textLabel.text = [NSString stringWithFormat:@"%ld",indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//    Class puchClass = NSClassFromString(@"CommunityQuestionListC");
//    PushVC([puchClass new]);
}

-(void)getUserMessageList
{
    NSMutableDictionary *param = [NSMutableDictionary new];
    param[@"page"] = @(self.pageNo);
    param[@"type"] = @(2);//消息类型：0关注1点赞2收藏
    NSString *url = @"api/user/notification";
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //2.0秒后追加任务代码到主队列，并开始执行
        //打印当前线程
//        NSLog(@"after---%@",[NSThread currentThread]);
        self.dataCount += 20;
        [self.tableView reloadData];
        [self.tableView.mj_footer endRefreshing];
    });
    
}


- (UIScrollView *)listScrollView {
    return self.tableView;
}

- (UIView *)listView {
    return self.view;
}

- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
    self.scrollCallback = callback;
}



- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    self.scrollCallback(scrollView);
}


@end
